<?php require_once('../../Connections/cotiza.php'); ?>
<?php
$campo   = $_GET['campo'];
$campo1  = $_GET['campo1'];
$flag    = $_GET['flag'];
$label   = $_GET['label'];
$cliente = $_GET['cliente'];

$acc   = $_GET['acc'];
mysql_select_db($database_cotiza, $cotiza);

if($acc == "search")
{
	$b = $_POST['busqueda'];
	$query = "SELECT * FROM mat_mstr WHERE mat_id like '%$b%' or mat_desc like '%$b%' ORDER BY mat_id";
}
else
	//$query = "SELECT solic_contacto, solic_cargo, solic_telefono, solic_email FROM solic_mstr WHERE solic_contacto = (SELECT DISTINCT solic_contacto FROM solic_mstr WHERE solic_cliente = '$cliente' AND solic_contacto IS NOT NULL) ORDER BY solic_contacto";
	$query = "SELECT DISTINCT solic_contacto FROM solic_mstr WHERE solic_cliente = '$cliente' AND solic_contacto IS NOT NULL ORDER BY solic_fecha Asc";
	
$busqueda = mysql_query($query, $cotiza) or die(mysql_error());
$row = mysql_fetch_assoc($busqueda);
$totalRows = mysql_num_rows($busqueda);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>..:: Contactos ::..</title>
<link href="../../main.css" rel="stylesheet" type="text/css" />
<script>
function retornar(cod,cargo,telefono,email)
{
	var campo  = '<?php echo $campo;  ?>';
	
	window.opener.document.getElementById(campo).value= cod;
	window.opener.document.getElementById('cargo').value= cargo;
	window.opener.document.getElementById('telefono').value= telefono;
	window.opener.document.getElementById('email').value= email;
	window.opener.document.getElementById('email').focus();
	<?php if($label <> "") echo "window.opener.document.getElementById('$label').innerHTML = desc;"; ?>
	
	window.close();	
}

</script>
<style type="text/css">
<!--
.default_title {
	color: #FFF;
}
-->
</style>
</head>

<body onload="document.form1.busqueda.focus();">
<form id="form1" name="form1" method="post" action="materiales.php?campo=<?php echo $campo; ?>&acc=search&label=<?php echo $label;?>">
  <table border="0" align="center">
    <tr>
      <td >B&uacute;squeda de Contacto:</td>
      <td ><input name="busqueda" class="default" size="20" autocomplete="off" value="<?php echo $b;?>" /></td>
      <td ><input type="submit" value="Buscar" class="v8" /></td>
    </tr>
  </table>
</form>
<br />
<?php if($totalRows >0){?>
  <table width="375" border="1" align="center" cellpadding="2" cellspacing="0">
    <tr class="default_title">
      <td width="86" align="center" bgcolor="#0000CC">Nombre</td>
      <td width="72" align="center" bgcolor="#0000CC">Cargo</td>
      <td width="68" align="center" bgcolor="#0000CC">Tel&eacute;fono</td>
      <td width="123" align="center" bgcolor="#0000CC">E-mail</td>
    </tr>
    <?php do { 
			$query = "SELECT solic_cargo, solic_telefono, solic_email FROM solic_mstr WHERE solic_contacto = '".$row['solic_contacto']."' ORDER BY solic_fecha";
			$contactos = mysql_query($query, $cotiza) or die(mysql_error());
			$contacto = mysql_fetch_assoc($contactos);
			$totalContactos = mysql_num_rows($contactos);
	
	?>
    <tr>
      <td width="86"><a href="javascript:retornar('<?php echo $row['solic_contacto']; ?>','<?php echo $contacto['solic_cargo']; ?>','<?php echo $contacto['solic_telefono']; ?>','<?php echo $contacto['solic_email']; ?>');"> <?php echo $row['solic_contacto']; ?> </a>&nbsp;</td>
      <td width="72"><?php echo $contacto['solic_cargo']; ?>&nbsp;</td>
      <td width="68"><?php echo $contacto['solic_telefono']; ?>&nbsp;</td>
      <td width="123"><?php echo $contacto['solic_email']; ?>&nbsp;</td>
    </tr>
      <?php } while ($row = mysql_fetch_assoc($busqueda)); ?>
  </table>
<?php }?>
</body>
</html>
<?php 
mysql_close($cotiza);
?>